package com.weixin.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.weixin.dao.Role_TbDAO;
import com.weixin.dao.User_Role_TbDAO;
import com.weixin.dao.User_TbDAO;
import com.weixin.dao.impl.Role_TbDAOImpl;
import com.weixin.dao.impl.User_Role_TbDAOImpl;
import com.weixin.dao.impl.User_TbDAOImpl;
import com.weixin.entity.Role_Tb;

import com.weixin.entity.User_Role_Tb;
import com.weixin.entity.User_Tb;

import com.weixin.service.User_TbService;

public class User_tbServiceImpl implements User_TbService {
	User_TbDAO td=new User_TbDAOImpl();
	  User_Role_TbDAO ur=new User_Role_TbDAOImpl();
	  Role_TbDAO rt=new Role_TbDAOImpl();
	@Override
	public List<User_Tb> getAll() throws SQLException {
		// TODO Auto-generated method stub
		return td.seletct();
	}
	@Override
	public boolean add(User_Tb user_tb) throws SQLException {
		// TODO Auto-generated method stub
		 int u_id = td.insert(user_tb);
	     int r_id  = rt.selectByTitle(user_tb.getRole());
	     User_Role_Tb rtb=new User_Role_Tb();
	     rtb.setUser_id(u_id);
	     rtb.setRole_id(r_id);
	     
		return ur.insert(rtb);
		
	}
	@Override
	public boolean deleteById(int id) throws SQLException {
		// TODO Auto-generated method stub
		
		return td.delete(id);
	}
	@Override
	public boolean updateSelect(User_Tb user_tb) throws SQLException {
		// TODO Auto-generated method stub
		return td.update(user_tb);
	}
	@Override
	public User_Tb getById(int id) throws SQLException {
		// TODO Auto-generated method stub
		return td.getById(id);
	}
	@Override
	public User_Tb selectmp(String name, String password) throws SQLException {
		// TODO Auto-generated method stub
		return td.selectmp(name, password);
	}
	@Override
	public List<User_Tb> listByRole(String role) throws SQLException {
		// TODO Auto-generated method stub
		return td.listRole(role);
	}
	@Override
	public boolean deleteAll(List<String> ids) throws SQLException {
		// TODO Auto-generated method stub
		if (ur.deleteAllByUids(ids)) {
		return	td.deleteAll(ids);
		}
		return false;
	}
	@Override
	public List<User_Tb> listAllByRolePagination(String role, int pageSize, int pageNum) throws SQLException {
		// TODO Auto-generated method stub
			return td.selectAllByRolePagination(role, pageSize, pageNum);
		
	}
	@Override
	public int getTotal(String role) throws SQLException {
		// TODO Auto-generated method stub
		return td.selectTotal(role);
	}
	
	@Override
	public List<User_Tb> selectAllByRoleSearchPagination(String role, String search, int pageSize, int pageNum)
			throws SQLException {
		// TODO Auto-generated method stub
		return td.selectAllByRoleSearchPagination(role, search, pageSize, pageNum);
	}
	@Override
	public List<User_Tb> listAllByRoleSearchPagination(String role, String search, int pageSize, int pageNum)
			throws SQLException {
		// TODO Auto-generated method stub
		return td.selectAllByRoleSearchPagination(role, search, pageSize, pageNum);
	}
	@Override
	public double getTotalBySearch(String role, String search) throws SQLException {
		// TODO Auto-generated method stub
		return td.selectTotalBySearch(role, search);
	}
	@Override
	public User_Tb xiugai(String name) throws SQLException {
		// TODO Auto-generated method stub
		return td.xiugai(name);
	}
	@Override
	public User_Tb yz(String question1, String answer1, String question2, String answer2, String name)
			throws SQLException {
		// TODO Auto-generated method stub
		return td.yz(question1, answer1, question2, answer2, name);
	}
	@Override
	public boolean pwdnew(User_Tb user_tb) throws SQLException {
		// TODO Auto-generated method stub
		return td.pwdnew(user_tb);
	}


	
	
	
    
}
